package com.snakegame.config;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 地图类，定义游戏地图的属性和方法
 */
public class Map {
    private String name;
    private int width;
    private int height;
    private List<Point> walls;
    private Point snake1StartPosition;
    private Direction snake1StartDirection;
    private Point snake2StartPosition;
    private Direction snake2StartDirection;
    
    public Map(String name, int width, int height) {
        this.name = name;
        this.width = width;
        this.height = height;
        this.walls = new ArrayList<>();
        
        // 设置默认的蛇起始位置和方向
        snake1StartPosition = new Point(width / 4, height / 2);
        snake1StartDirection = Direction.RIGHT;
        
        snake2StartPosition = new Point(width * 3 / 4, height / 2);
        snake2StartDirection = Direction.LEFT;
    }
    
    public void addWall(int x, int y) {
        walls.add(new Point(x, y));
    }
    
    public boolean isWall(Point point) {
        return walls.contains(point) || 
               point.x < 0 || point.x >= width || 
               point.y < 0 || point.y >= height;
    }
    
    // Getters and Setters
    public String getName() {
        return name;
    }
    
    public int getWidth() {
        return width;
    }
    
    public int getHeight() {
        return height;
    }
    
    public List<Point> getWalls() {
        return walls;
    }
    
    public Point getSnake1StartPosition() {
        return snake1StartPosition;
    }
    
    public void setSnake1StartPosition(Point snake1StartPosition) {
        this.snake1StartPosition = snake1StartPosition;
    }
    
    public Direction getSnake1StartDirection() {
        return snake1StartDirection;
    }
    
    public void setSnake1StartDirection(Direction snake1StartDirection) {
        this.snake1StartDirection = snake1StartDirection;
    }
    
    public Point getSnake2StartPosition() {
        return snake2StartPosition;
    }
    
    public void setSnake2StartPosition(Point snake2StartPosition) {
        this.snake2StartPosition = snake2StartPosition;
    }
    
    public Direction getSnake2StartDirection() {
        return snake2StartDirection;
    }
    
    public void setSnake2StartDirection(Direction snake2StartDirection) {
        this.snake2StartDirection = snake2StartDirection;
    }
}    